<?php

namespace app\admin\validate;

use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Validate;

class Talent extends Validate
{
    protected $rule = [
        'name' => 'require',
        'nation' => 'require|checkCategory',
        'birthday' => 'require',
        'gender' => 'require',
        'native_place' => 'require',
        'politics' => 'require|checkCategory',
        'education' => 'require|checkCategory',
        'status' => 'require',
        'id' => 'require',
    ];

    protected $scene=[
        'create'=>['name','nation','birthday','gender','native_place','politics','education','status'],
        'update'=>['name','nation','birthday','gender','native_place','politics','education','status','id'],
    ];

    protected $message = [
        'name' => '姓名不能为空',
        'nation' => '民族不能为空',
        'birthday' => '出生日期不能为空',
        'gender' => '性别不能为空',
        'native_place' => '籍贯不能为空',
        'politics' => '政治面貌不能为空',
        'education' => '学历不能为空',
        'status' => '状态不能为空',
        'id' => 'ID不能为空',
    ];
    /**
     * @param $value
     * @param $rule
     * @param array $data
     * @return string|true
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    protected function checkCategory($value, $rule, array $data = [])
    {
        $category=(new \app\common\business\Category())->categoryDictionaries();
        if(!isset($category[$value])){
            return '类别不存在';
        }
        return true;
    }
}
